<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class OrderAcm implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
     protected $mch_id,$amount;

    /**
     * OrderAcm constructor.
     * @param $mch_id
     * @param $amount
     */
    public function __construct($mch_id,$amount)
    {
        $this->mch_id = $mch_id;
        $this->amount=$amount;
    }

    /**


    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $find_daily= \App\OrderAcm::whereDate('created_at',date('Y-m-d'))->where('mch_id',$this->mch_id)->first();
        if (!$find_daily){
            $data=[
                'mch_id'=>$this->mch_id,
                'date'=>date('Y-m-d'),
                'awaiting_order_number'=>1,
                'total_amount'=>0,
                'total_order_number'=>1
            ];
            \App\OrderAcm::create($data);
        }else{
            $find_daily->awaiting_order_number+=1;
            $find_daily->save();
        }
            if ($this->attempts()>3){
                $this->delete();
            }
            $this->delete();

    }
}
